import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'app_colors.dart';

//仿照AppBar，对于没有状态栏的页面，使用此组件
class StatusBarRegion extends StatelessWidget {
  final Widget child;
  final SystemUiOverlayStyle? systemOverlayStyle;

  const StatusBarRegion({super.key, required this.child, this.systemOverlayStyle});

  @override
  Widget build(BuildContext context) {
    final AppBarTheme appBarTheme = AppBarTheme.of(context);
    final SystemUiOverlayStyle overlayStyle = systemOverlayStyle ?? appBarTheme.systemOverlayStyle ?? StatusBar.light;
    return AnnotatedRegion(value: overlayStyle, child: child);
  }
}

class StatusBar {
  StatusBar._();

  static const SystemUiOverlayStyle light = SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    systemNavigationBarColor: ColorsApp.page_background,
    //android使用
    systemNavigationBarIconBrightness: Brightness.dark,
    //android使用
    statusBarIconBrightness: Brightness.dark,
    //ios使用
    statusBarBrightness: Brightness.light,
  );

  static const SystemUiOverlayStyle dark = SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    systemNavigationBarColor: ColorsApp.page_background,
    //android使用
    systemNavigationBarIconBrightness: Brightness.light,
    //android使用
    statusBarIconBrightness: Brightness.light,
    //ios使用
    statusBarBrightness: Brightness.dark,
  );

  static SystemUiOverlayStyle get statusBarStyle => light;

  static void setStatusBar(bool isDark) {
    if (isDark) {
      // 状态栏深色
      SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
    } else {
      SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
    }
  }

  //启动页面样式
  static void setWelcomeStatusBar() {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      systemNavigationBarColor: Colors.transparent,
      systemNavigationBarIconBrightness: Brightness.dark,
      statusBarIconBrightness: Brightness.dark,
      statusBarBrightness: Brightness.dark,
    ));
  }
}
